package edu.ck.drawTest;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

public class drawTest extends Activity {
    /** Called when the activity is first created. */
	private TickHandler tickHandler;
	private drawView dView;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        dView = new drawView(this);
        setContentView(dView);
    }
    
    @Override
    public void onResume(){
    	super.onResume();
    	tickHandler = new TickHandler();
    	tickHandler.sleep(0);
    }
    
    @Override
    public void onPause(){
    	super.onPause();
    	tickHandler = null;
    }    
    
    public class TickHandler extends Handler{
    	
       	@Override
    	public void handleMessage(Message msg){
    		dView.invalidate();
    		if(tickHandler != null) tickHandler.sleep(100);
    	}
    	
    	public void sleep(long delayMills){
    		removeMessages(0);
    		sendMessageDelayed(obtainMessage(0), delayMills);
    	}
    }
}